package com.test.design.pattern.objserver;

import java.util.ArrayList;

/**
 * @ClasName SubscriptionSubject
 * @Descripution TODO 具体主题角色类
 * @Author USER
 * @Date 2022/2/24 14:11
 * @Version V1.0
 */
public class SubscriptionSubject implements Subject{

    ArrayList<Observer>  weiXinUserList = new ArrayList<Observer>();

    public void attach(Observer observer) {
        weiXinUserList.add(observer);
    }

    public void detach(Observer observer) {
        weiXinUserList.remove(observer);
    }

    public void notify(String message) {
        //遍历集合
        for (Observer observer : weiXinUserList) {
            //调用观察者对象中的update方法
            observer.update(message);
        }
    }
}
